import { existsSync, rmSync } from 'fs'
import { join } from 'path'

// 定义要清理的目录和文件
const pathsToClean = [
  'node_modules',
  'packages/components/node_modules',
  'packages/common/node_modules',
  'packages/theme-chalk/node_modules',
  'packages/utils/node_modules',
  'packages/zl-crud/node_modules',
  'play/node_modules',
  'docs/node_modules',
  'internal/build/node_modules',
]

function clean() {
  console.log('开始清理项目...')

  for (const relativePath of pathsToClean) {
    const fullPath = join(process.cwd(), relativePath)

    try {
      if (existsSync(fullPath)) {
        console.log(`正在删除: ${relativePath}`)
        rmSync(fullPath, { recursive: true, force: true })
      } else {
        console.log(`路径不存在(已跳过): ${relativePath}`)
      }
    } catch (error) {
      console.error(`删除失败 ${relativePath}:`, error.message)
    }
  }

  console.log('清理完成!')
}

clean()
